package rjeutsky.ui;

import java.io.PrintStream;
import java.util.List;
import java.util.Scanner;

import rjeutsky.ui.models.MenuItem;

public class ConsoleMenu {
	private List<MenuItem> menu;
	private PrintStream console = System.out;
	private Scanner input = new Scanner(System.in);
	
	public ConsoleMenu(List<MenuItem> menu){
		this.menu = menu;
	}
	
	public void printMenu(){
		for (MenuItem item : menu){
			console.println(String.format("%1$s - %2$s", 
					item.getKey(), item.getDescription()));
		}
	}
	
	public void processMenu(){
		boolean proceedFlag = true;
		while (proceedFlag){
			String line = input.nextLine();
			for (MenuItem item : menu){
				if (line.equalsIgnoreCase(item.getKey())){
					proceedFlag &= item.getAction().doAction();
				}
			}
		}
	}

	public List<MenuItem> getMenu() {
		return menu;
	}

	public void setMenu(List<MenuItem> menu) {
		this.menu = menu;
	}
}
